
var itstock_page_headers = new Object;

function itstock_page_request(page, id, post) {
  if(post === undefined){post = "";}
  if(id === undefined){id = "";}else{
    post = 'id='+id + post;
  }
  if(itstock_request_popup(page, post, 500, 500, itstock_page_headers[page] === undefined)){
    itstock_page_headers[page] = false;
  }
}

function itstock_locations(page, elm ,idx, search, post) {
  var lb_id = undefined;
  var data = "";
  if(idx !== undefined && idx !== null){data = "&idx="+idx;}
  if(search !== undefined) {
    var value = encodeURIComponent(E('search_ajax').value);
    if(!regex_text.test(value)){data = data + "&search="+value;}
  }
  if(elm !== undefined && elm !== null){
    lb_id = itstock_lightbox_get_id(elm);
  }
  if(itstock_request_popup(page + data, post, 600, 500, itstock_page_headers[page] === undefined, lb_id)){
    itstock_page_headers[page] = false;
  }
}

function itstock_location_btn(){
  E('location_row').style.display = '';
  var options = E('category_id').options;
  var outcase = A(options[options.selectedIndex], 'data-outcase');
  A(E('location_btn'),'onclick',"itstock_locations('"+(outcase === '1'?'locations':'cpus')+"')");
  if(regex_text.test(A(E('location_set'), 'data-outcase'))) {
    A(E('location_set'), 'data-outcase', outcase);
  } else {
    if(E('location_set').value === '1' && A(E('location_set'), 'data-outcase') !== outcase){
      E('e_msg').innerHTML = 'Please select a valid location.';
      E('e_msg').style.display = '';
      E('location_set').value = '';
    } else {
      E('e_msg').style.display = 'none';
      A(E('location_set'), 'data-outcase', outcase);
    }
  }
}

function itstock_set_location(elm, id, type) {
  var xmlhttp = xml_http_request('id='+id+'&type='+type, 'request.php?page=set_location');
  if(xmlhttp.status === 200){
    E('location_info').innerHTML = xmlhttp.responseText;
    E('location_set').value = '1';
  } else if(xmlhttp.status === 403) {
    window.location = "index.php";
  }else{
    E('location_info').innerHTML = '<p class="error">'+xmlhttp.responseText+'</p>';
    E('location_set').value = '';
  }
  itstock_lightbox_close(null, elm);
}
